package com.edfu.core.controller;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.edfu.core.identitymgt.service.api.IIdentityMgtService;
import com.edfu.core.identitymgt.vo.Permission;
import com.edfu.core.identitymgt.vo.Role;
import com.edfu.core.identitymgt.vo.RolePermission;
import com.edfu.core.identitymgt.vo.User;
import com.edfu.core.identitymgt.vo.UserEnrollment;
import com.edfu.core.util.EduServiceFactory;
import com.edfu.core.util.Response;

@Controller
@RequestMapping("/identitymgt")
public class IdentityMgtController implements IIdentityMgtService {

	@Override
	public void addRole(Role role) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public User getUser(String userId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addUser(User user) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean userExists(String userId) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void enrollUser(UserEnrollment enrollment) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public @ResponseBody Response addMember(UserEnrollment member, String enrollmentCtxType, String enrollmentCtxId) {
		Response r = null ;
		try {
			r = EduServiceFactory.getIdentityMgtService().addMember(member, enrollmentCtxType, enrollmentCtxId);
		}catch ( Exception e ) {
			r = _getFailureResponse(e);
		}
		return r;
	}
	
	private Response _getFailureResponse(Exception e) {
		Response response = new Response();
		response.setSuccessful(false);
		response.setResponseCode("Internal Application Error.");
		response.setResponseMessage(e.getMessage());
		return response;
	}

	@Override
	public boolean isUserEnrolled(String userId, String roleName) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void addPermission(Permission permission) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void assignPermission(RolePermission rolePermission) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Collection<GrantedAuthority> getAuthorities(String userId) {
		// TODO Auto-generated method stub
		return null;
	}


}
